
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>19.  Gnu Sed {replacement-string}标志 · Sed-and-Awk-101-Hacks</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="devops007">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-terminal/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../part3/" />
    
    
    <link rel="prev" href="multiple_group.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://linuxer.io" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    序言
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第一章 Sed语法和基本命令</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../part1/">
            
                <a href="../part1/">
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../part1/syntax.html">
            
                <a href="../part1/syntax.html">
            
                    
                    1. Sed命令语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../part1/script.html">
            
                <a href="../part1/script.html">
            
                    
                    2. Sed脚本流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../part1/pattern.html">
            
                <a href="../part1/pattern.html">
            
                    
                    3. 打印模式空间(p 命令)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../part1/delete.html">
            
                <a href="../part1/delete.html">
            
                    
                    4. 删除行(d 命令)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../part1/write.html">
            
                <a href="../part1/write.html">
            
                    
                    5. 模式空间写入文件(w 命令)
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第二章 Sed替换命令</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="./">
            
                <a href="./">
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="syntax.html">
            
                <a href="syntax.html">
            
                    
                    6. Sed替换命令语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="global.html">
            
                <a href="global.html">
            
                    
                    7. 全局标志（g flag）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="number.html">
            
                <a href="number.html">
            
                    
                    8. 数字标志（1,2,3...flag）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="print.html">
            
                <a href="print.html">
            
                    
                    9. 打印标志（p falg）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="write.html">
            
                <a href="write.html">
            
                    
                    10. 写标志（w falg）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="ignore.html">
            
                <a href="ignore.html">
            
                    
                    11. 忽略大小写标志（i falg）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="exec.html">
            
                <a href="exec.html">
            
                    
                    12. 执行标志（e falg）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="combine.html">
            
                <a href="combine.html">
            
                    
                    13. sed替换标志组合使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="delimiter.html">
            
                <a href="delimiter.html">
            
                    
                    14. sed替换定界符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="multiple.html">
            
                <a href="multiple.html">
            
                    
                    15. 多个替换命令作用到同一行上
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="pattern.html">
            
                <a href="pattern.html">
            
                    
                    16. &魅力 - 引用匹配模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="single_group.html">
            
                <a href="single_group.html">
            
                    
                    17. 分组替换（单一组）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.14" data-path="multiple_group.html">
            
                <a href="multiple_group.html">
            
                    
                    18. 分组替换（多组）
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="3.15" data-path="string.html">
            
                <a href="string.html">
            
                    
                    19.  Gnu Sed {replacement-string}标志
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第三章 Sed正则表达式</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../part3/">
            
                <a href="../part3/">
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../part3/syntax.html">
            
                <a href="../part3/syntax.html">
            
                    
                    20. 正则表达式基本原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../part3/additional.html">
            
                <a href="../part3/additional.html">
            
                    
                    21. 扩展正则表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../part3/substitution.html">
            
                <a href="../part3/substitution.html">
            
                    
                    22. Sed基于正则表达式的替换
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第四章 Sed的执行</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../part4/">
            
                <a href="../part4/">
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../part4/multiplecmd.html">
            
                <a href="../part4/multiplecmd.html">
            
                    
                    23. 命令行中的多个Sed命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../part4/script.html">
            
                <a href="../part4/script.html">
            
                    
                    24. Sed脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../part4/comment.html">
            
                <a href="../part4/comment.html">
            
                    
                    25. Sed注释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../part4/interpreter.html">
            
                <a href="../part4/interpreter.html">
            
                    
                    26. Sed解释执行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../part4/modifying.html">
            
                <a href="../part4/modifying.html">
            
                    
                    27. 直接将修改应用到输入文件
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第五章 Sed扩展命令</li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../part5/">
            
                <a href="../part5/">
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../part5/append.html">
            
                <a href="../part5/append.html">
            
                    
                    28. 行后追加（a 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="../part5/insert.html">
            
                <a href="../part5/insert.html">
            
                    
                    29. 行前追加（i 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="../part5/change.html">
            
                <a href="../part5/change.html">
            
                    
                    30. 改变行（c 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="../part5/combine.html">
            
                <a href="../part5/combine.html">
            
                    
                    31. a、i、c 命令结合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="../part5/hidden.html">
            
                <a href="../part5/hidden.html">
            
                    
                    32. 打印隐藏字符（l 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="../part5/linenumber.html">
            
                <a href="../part5/linenumber.html">
            
                    
                    33. 打印行号（= 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="../part5/case.html">
            
                <a href="../part5/case.html">
            
                    
                    34. 改变大小写（y 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.9" data-path="../part5/multiple.html">
            
                <a href="../part5/multiple.html">
            
                    
                    35. 指定多个输入文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.10" data-path="../part5/quit.html">
            
                <a href="../part5/quit.html">
            
                    
                    36. 退出（q 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.11" data-path="../part5/read.html">
            
                <a href="../part5/read.html">
            
                    
                    37. 读取额外文件（r 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.12" data-path="../part5/unix.html">
            
                <a href="../part5/unix.html">
            
                    
                    38. 模拟Unix命令（cat、grep、head）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.13" data-path="../part5/option.html">
            
                <a href="../part5/option.html">
            
                    
                    39. sed命令行参数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.14" data-path="../part5/patter.html">
            
                <a href="../part5/patter.html">
            
                    
                    40. 打印模式空间（n 命令）
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第六章 Sed的保持空间和模式空间命令</li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="../part6/">
            
                <a href="../part6/">
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="../part6/swap.html">
            
                <a href="../part6/swap.html">
            
                    
                    41. 交换模式空间与保持空间（x 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="../part6/copyp2h.html">
            
                <a href="../part6/copyp2h.html">
            
                    
                    42. 拷贝模式空间到保持空间（h 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="../part6/appendp2h.html">
            
                <a href="../part6/appendp2h.html">
            
                    
                    43. 追加模式空间到保持空间（H 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="../part6/copyh2p.html">
            
                <a href="../part6/copyh2p.html">
            
                    
                    44. 拷贝保持空间到模式空间（g 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="../part6/appendh2p.html">
            
                <a href="../part6/appendh2p.html">
            
                    
                    45. 追加保持空间到模式空间（G 命令）
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第七章 Sed多命令行和循环</li>
        
        
    
        <li class="chapter " data-level="8.1" data-path="../part7/">
            
                <a href="../part7/">
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="../part7/append.html">
            
                <a href="../part7/append.html">
            
                    
                    46. 追加下一行到模式空间（N 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="../part7/print.html">
            
                <a href="../part7/print.html">
            
                    
                    47. 在MultiLine中打印第一行（P 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="../part7/delete.html">
            
                <a href="../part7/delete.html">
            
                    
                    48. 在MultiLine中删除第一行（D 命令）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="../part7/loop_and_branch.html">
            
                <a href="../part7/loop_and_branch.html">
            
                    
                    49. 循环和分支（b 命令和 ：label）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="../part7/loop_t.html">
            
                <a href="../part7/loop_t.html">
            
                    
                    50. 循环使用t命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第八章 Awk语法和基本命令</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../part8/README.md">
            
                <span>
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="../part8/syntax.md">
            
                <span>
            
                    
                    51. Awk命令语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="../part8/structure.md">
            
                <span>
            
                    
                    52. Awk程序结构（BEGIN, body, END, block）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.4" data-path="../part8/print.md">
            
                <span>
            
                    
                    53. 打印命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.5" data-path="../part8/regex.md">
            
                <span>
            
                    
                    54. 模式匹配
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第九章 Awk内置变量</li>
        
        
    
        <li class="chapter " data-level="10.1" data-path="../part9/README.md">
            
                <span>
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="../part9/input-field-sep.md">
            
                <span>
            
                    
                    55. FS - 输入字段分隔符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="10.3" data-path="../part9/output-field-sep.md">
            
                <span>
            
                    
                    56. OFS - 输出字段分隔符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="10.4" data-path="../part9/record-sep.md">
            
                <span>
            
                    
                    57. RS - 记录分隔符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="10.5" data-path="../part9/output-record-sep.md">
            
                <span>
            
                    
                    58. ORS - 输出记录分隔符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="10.6" data-path="../part9/record-num.md">
            
                <span>
            
                    
                    59. NR - 当前记录数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="10.7" data-path="../part9/filename.md">
            
                <span>
            
                    
                    60. FILENAME - 当前输入文件名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="10.8" data-path="../part9/file-record-num.md">
            
                <span>
            
                    
                    61. FNR - 文件总记录数
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第十章 Awk变量和运算符</li>
        
        
    
        <li class="chapter " data-level="11.1" data-path="../part10/README.md">
            
                <span>
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="11.2" data-path="../part10/variable.md">
            
                <span>
            
                    
                    62. 变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="11.3" data-path="../part10/unary-op.md">
            
                <span>
            
                    
                    63. 一元运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="11.4" data-path="../part10/arithmetic-op.md">
            
                <span>
            
                    
                    64. 算术运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="11.5" data-path="../part10/string-op.md">
            
                <span>
            
                    
                    65. 字符串运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="11.6" data-path="../part10/assigment-op.md">
            
                <span>
            
                    
                    66. 赋值运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="11.7" data-path="../part10/compare-op.md">
            
                <span>
            
                    
                    67. 比较运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="11.8" data-path="../part10/regex-op.md">
            
                <span>
            
                    
                    68. 正则表达式运算符
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第十一章 Awk条件和循环语句</li>
        
        
    
        <li class="chapter " data-level="12.1" data-path="../part11/README.md">
            
                <span>
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="../part11/if.md">
            
                <span>
            
                    
                    69. If 条件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.3" data-path="../part11/if-else.md">
            
                <span>
            
                    
                    70. If-Else 条件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.4" data-path="../part11/while.md">
            
                <span>
            
                    
                    71. While 循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.5" data-path="../part11/do-while.md">
            
                <span>
            
                    
                    72. Do-While 循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.6" data-path="../part11/for.md">
            
                <span>
            
                    
                    73. For 循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.7" data-path="../part11/break.md">
            
                <span>
            
                    
                    74. Break 终止循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.8" data-path="../part11/continue.md">
            
                <span>
            
                    
                    75. Continue 继续循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.9" data-path="../part11/exit.md">
            
                <span>
            
                    
                    76. Exit 退出
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第十二章 Awk内置数组</li>
        
        
    
        <li class="chapter " data-level="13.1" data-path="../part12/README.md">
            
                <span>
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="13.2" data-path="../part12/assigning-array.md">
            
                <span>
            
                    
                    77. 分配数组元素
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="13.3" data-path="../part12/refer-array.md">
            
                <span>
            
                    
                    78. 引用数组元素
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="13.4" data-path="../part12/loop-access-array.md">
            
                <span>
            
                    
                    79. 循环遍历数组元素
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="13.5" data-path="../part12/delete-array.md">
            
                <span>
            
                    
                    80. 删除数组元素
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="13.6" data-path="../part12/multi-dimensional-array.md">
            
                <span>
            
                    
                    81. 多维数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="13.7" data-path="../part12/subscript-sep.md">
            
                <span>
            
                    
                    82. SUBSEP - 下标分隔符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="13.8" data-path="../part12/sort-array-by-value.md">
            
                <span>
            
                    
                    83. asort - 数组值排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="13.9" data-path="../part12/sort-array-by-index.md">
            
                <span>
            
                    
                    84. asorti - 数组索引排序
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第十三章 Awk附加命令</li>
        
        
    
        <li class="chapter " data-level="14.1" data-path="../part13/README.md">
            
                <span>
            
                    
                    说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.2" data-path="../part13/printf.md">
            
                <span>
            
                    
                    85. printf - 格式化打印
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.3" data-path="../part13/number-function.md">
            
                <span>
            
                    
                    86. 内置数学函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.4" data-path="../part13/random-number.md">
            
                <span>
            
                    
                    87. 随机数构造
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.5" data-path="../part13/string-function.md">
            
                <span>
            
                    
                    88. 通用字符串函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.6" data-path="../part13/gawk-nawk.md">
            
                <span>
            
                    
                    89. GAWK / NAWK 字符串函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.7" data-path="../part13/gawk-string-function.md">
            
                <span>
            
                    
                    90. GAWK 字符串函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.8" data-path="../part13/argument-processing.md">
            
                <span>
            
                    
                    91. 参数处理（ARGC，ARGV，ARGIND）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.9" data-path="../part13/ofmt-variable.md">
            
                <span>
            
                    
                    92. OFMT - 内置变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.10" data-path="../part13/gawk-built-in-variable.md">
            
                <span>
            
                    
                    93. GAWK内置环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.11" data-path="../part13/pgawk.md">
            
                <span>
            
                    
                    94. pgawk - Awk配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.12" data-path="../part13/bit-manipulation.md">
            
                <span>
            
                    
                    95. 位操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.13" data-path="../part13/user-defined-funtion.md">
            
                <span>
            
                    
                    96. 用户自定义函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.14" data-path="../part13/internationalization.md">
            
                <span>
            
                    
                    97. 语言无关输出（国际化）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.15" data-path="../part13/communication.md">
            
                <span>
            
                    
                    98. 双向通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.16" data-path="../part13/system-function.md">
            
                <span>
            
                    
                    99. 系统函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.17" data-path="../part13/timestamp.md">
            
                <span>
            
                    
                    100. 时间戳函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="14.18" data-path="../part13/getline-command.md">
            
                <span>
            
                    
                    101. getline 命令
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >19.  Gnu Sed {replacement-string}标志</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><span class="title-icon "></span><a href="#gnu-sed-replacement-string&#x6807;&#x5FD7;"><b>1. </b>Gnu Sed {replacement-string}&#x6807;&#x5FD7;</a></li><ul><li><span class="title-icon "></span><a href="#l"><b>1.1. </b>\l</a></li><li><span class="title-icon "></span><a href="#l_1"><b>1.2. </b>\L</a></li><li><span class="title-icon "></span><a href="#u"><b>1.3. </b>\u</a></li><li><span class="title-icon "></span><a href="#u_1"><b>1.4. </b>\U</a></li><li><span class="title-icon "></span><a href="#e"><b>1.5. </b>\E</a></li></ul><li><span class="title-icon "></span><a href="#replacement-string&#x6807;&#x5FD7;&#x7684;&#x7528;&#x6CD5;"><b>2. </b>{replacement-string}&#x6807;&#x5FD7;&#x7684;&#x7528;&#x6CD5;</a></li></ul></div><a href="#gnu-sed-replacement-string&#x6807;&#x5FD7;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="gnu-sed-replacement-string&#x6807;&#x5FD7;"><a name="gnu-sed-replacement-string&#x6807;&#x5FD7;" class="anchor-navigation-ex-anchor" href="#gnu-sed-replacement-string&#x6807;&#x5FD7;"><i class="fa fa-link" aria-hidden="true"></i></a>1. Gnu Sed {replacement-string}&#x6807;&#x5FD7;</h1>
<p>&#x8FD9;&#x4E9B;&#x6807;&#x5FD7;&#x4EC5;&#x5728;sed&#x7684;GNU&#x7248;&#x672C;&#x4E2D;&#x53EF;&#x7528;&#x3002;&#x5B83;&#x4EEC;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;sed&#x66FF;&#x6362;&#x547D;&#x4EE4;&#x7684;{replacement-string}&#x90E8;&#x5206;&#x3002;</p>
<h2 id="l"><a name="l" class="anchor-navigation-ex-anchor" href="#l"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. \l</h2>
<p>&#x5F53;&#x4F60;&#x5728;{replacement-string}&#x90E8;&#x5206;&#x6307;&#x5B9A;\l&#xFF0C;&#x5B83;&#x5C06;&#x7D27;&#x8DDF;&#x5728;\l&#x4E0A;&#x7684;&#x5B57;&#x7B26;&#x89C6;&#x4E3A;&#x5C0F;&#x5199;&#x5B57;&#x6BCD;&#x3002; 
&#x4F60;&#x5DF2;&#x7ECF;&#x77E5;&#x9053;&#x4E0B;&#x9762;&#x8FD9;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50;&#x4F1A;&#x5C06;John&#x6539;&#x4E3A;JOHNNY&#x3002;<br></p>
<pre><code>sed &apos;s/John/JOHNNY/&apos; employee.txt
</code></pre><p>&#x4EE5;&#x4E0B;&#x793A;&#x4F8B;&#x5728;{replacement-string}&#x4E2D;&#x7684;H&#x4E4B;&#x524D;&#x5305;&#x542B;\l&#xFF08;&#x5373;JO\lHNNY&#xFF09;&#x3002; &#x8FD9;&#x53EA;&#x4F1A;&#x5C06;JOHNNY&#x4E2D;&#x7684;&#x5B57;&#x7B26;h&#x6539;&#x4E3A;&#x5C0F;&#x5199;&#x3002;</p>
<p><strong>&#x66FF;&#x6362;John &#x4E3A; JOhNNY</strong>:</p>
<pre><code>$ sed -n &apos;s/John/JO\lHNNY/p&apos; employee.txt
101,JOhNNY Doe,CEO
</code></pre><h2 id="l_1"><a name="l_1" class="anchor-navigation-ex-anchor" href="#l_1"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. \L</h2>
<p>&#x5F53;&#x4F60;&#x5728;{replacement-string}&#x90E8;&#x5206;&#x6307;&#x5B9A;\L&#xFF0C;&#x4F1A;&#x5C06;&#x5176;&#x4F59;&#x5B57;&#x7B26;&#x89C6;&#x4E3A;&#x5C0F;&#x5199;&#x5B57;&#x6BCD;&#x3002;<br></p>
<p>&#x4EE5;&#x4E0B;&#x793A;&#x4F8B;&#x5728;{replacement-string}&#x4E2D;&#x7684;H&#x4E4B;&#x524D;&#x5305;&#x542B;\L&#xFF08;&#x5373;JO\LHNNY&#xFF09;&#x3002;&#x8FD9;&#x5C06;&#x4F1A;&#x5176;&#x4F59;&#x7684;&#x5B57;&#x7B26;&#x4ECE;H&#x5F00;&#x59CB;&#x5168;&#x90E8;&#x53D8;&#x4E3A;&#x5C0F;&#x5199;&#x3002;</p>
<p><strong>&#x66FF;&#x6362;Johnny &#x4E3A; JOhnny</strong>:</p>
<pre><code>$ sed -n &apos;s/John/JO\LHNNY/p&apos; employee.txt
101,JOhnny Doe,CEO
</code></pre><h2 id="u"><a name="u" class="anchor-navigation-ex-anchor" href="#u"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. \u</h2>
<p>&#x7C7B;&#x4F3C;&#x4E0E;\l&#xFF0C;&#x4E0D;&#x8FC7;&#x662F;&#x53D8;&#x4E3A;&#x5927;&#x5199;&#x3002;&#x5728;{replacement-string}&#x4E2D;&#x6307;&#x5B9A;\u,&#x5B83;&#x4F1A;&#x5C06;&#x7D27;&#x8DDF;&#x5728;\u&#x540E;&#x9762;&#x7684;&#x5B57;&#x7B26;&#x89C6;&#x4E3A;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x3002;&#x4EE5;&#x4E0B;
&#x793A;&#x4F8B;&#x5728;{replacement-string}&#xFF08;&#x5373;jo\uhnny&#xFF09;&#x4E2D;&#x5728;h&#x4E4B;&#x524D;&#x5305;&#x542B;\u&#xFF0C;&#x8FD9;&#x5C06;&#x4F1A; johnny &#x4E2D;&#x7684;h&#x6539;&#x4E3A;&#x5927;&#x5199;&#x3002;</p>
<p><strong>&#x66FF;&#x6362;John &#x4E3A; joHnny</strong>:</p>
<pre><code>$ sed -n &apos;s/John/jo\uhnny/p&apos; employee.txt
101,joHnny Doe,CEO
</code></pre><h2 id="u_1"><a name="u_1" class="anchor-navigation-ex-anchor" href="#u_1"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. \U</h2>
<p>&#x5F53;&#x60A8;&#x5728;{replacement-string}&#x90E8;&#x5206;&#x4E2D;&#x6307;&#x5B9A;\U&#x65F6;&#xFF0C;&#x5B83;&#x4F1A;&#x5C06;&#x5176;&#x4F59;&#x5B57;&#x7B26;&#x89C6;&#x4E3A;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x3002; &#x4EE5;&#x4E0B;&#x793A;&#x4F8B;&#x5728;{replacement-string}&#xFF08;&#x5373;jo\Uhnny&#xFF09;&#x4E2D;h&#x4E4B;&#x524D;&#x5305;&#x542B;\U&#x3002;
&#x8FD9;&#x4F1A;&#x5C06;&#x5176;&#x4F59;&#x7684;&#x5B57;&#x7B26;&#x4ECE;johnny&#x4E2D;&#x7684;h&#x5F00;&#x59CB;&#x4EE5;&#x540E;&#x7684;&#x90E8;&#x5206;&#x5168;&#x90E8;&#x6539;&#x4E3A;&#x5927;&#x5199;&#x3002;</p>
<p><strong>&#x66FF;&#x6362;John to joHNNY</strong>:</p>
<pre><code>$ sed -n &apos;s/John/jo\Uhnny/p&apos; employee.txt
101,joHNNY Doe,CEO
</code></pre><h2 id="e"><a name="e" class="anchor-navigation-ex-anchor" href="#e"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. \E</h2>
<p>&#x8FD9;&#x5E94;&#x8BE5;&#x4E0E;\L&#x548C;\U&#x7EC4;&#x5408;&#x4F7F;&#x7528;&#xFF0C;&#x8FD9;&#x4F1A;&#x505C;&#x6B62;&#x7531;\L&#x548C;\U&#x542F;&#x52A8;&#x7684;&#x8F6C;&#x6362;&#x3002;&#x4EE5;&#x4E0B;&#x793A;&#x4F8B;&#x4EE5;&#x5927;&#x5199;&#x6253;&#x5370;
&#x6574;&#x4E2A;{replacement-string}&#x4E2D;&#x7684;&quot;Johnny Boy&quot;,&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x5728;{replacement-string}&#x5F00;&#x5934;&#x6709;\U&#x3002;</p>
<p><strong>&#x66FF;&#x6362;John &#x4E3A; JOHNNY BOY:</strong>:</p>
<pre><code>$ sed -n &apos;s/John/\UJohnny Boy/p&apos; employee.txt
101,JOHNNY BOY Doe,CEO
</code></pre><p><strong>&#x66FF;&#x6362;John &#x4E3A; JOHNNY Boy:</strong>:</p>
<pre><code>$ sed -n &apos;s/John/\UJohnny\E Boy/p&apos; employee.txt
101,JOHNNY Boy Doe,CEO
</code></pre><p>&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x53EA;&#x7528;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x6253;&#x5370;&quot;Johnny&quot;&#xFF0C;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x5728;&#x66FF;&#x6362;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7D27;&#x63A5;&#x5728;&quot;Johnny&quot;&#x4E4B;&#x540E;&#x6709;\ E&#x3002;</p>
<h1 id="replacement-string&#x6807;&#x5FD7;&#x7684;&#x7528;&#x6CD5;"><a name="replacement-string&#x6807;&#x5FD7;&#x7684;&#x7528;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#replacement-string&#x6807;&#x5FD7;&#x7684;&#x7528;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>2. {replacement-string}&#x6807;&#x5FD7;&#x7684;&#x7528;&#x6CD5;</h1>
<p>&#x4EE5;&#x4E0A;&#x9759;&#x6001;&#x793A;&#x4F8B;&#x4EC5;&#x7528;&#x4E8E;&#x4E86;&#x89E3;&#x8FD9;&#x4E9B;&#x5F00;&#x5173;&#x5982;&#x4F55;&#x5DE5;&#x4F5C;&#xFF0C;&#x4F46;&#x662F;&#xFF0C;&#x4E0E;&#x9759;&#x6001;&#x503C;&#x4E00;&#x8D77;&#x4F7F;&#x7528;&#x65F6;&#xFF0C;&#x6807;&#x5FD7;&#x6CA1;&#x6709;&#x592A;&#x5927;&#x4EF7;&#x503C;&#xFF0C;
&#x56E0;&#x4E3A;&#x60A8;&#x53EA;&#x9700;&#x8981;&#x5728;&#x9700;&#x8981;&#x7684;&#x786E;&#x5207;&#x60C5;&#x51B5;&#x4E0B;&#x8F93;&#x5165;&#x9759;&#x6001;&#x503C;&#x5373;&#x53EF;&#x3002;<br></p>
<p>&#x4E0E;&#x5206;&#x7EC4;&#x7ED3;&#x5408;&#x4F7F;&#x7528;&#x65F6;&#xFF0C;&#x6807;&#x5FD7;&#x975E;&#x5E38;&#x6709;&#x7528;&#x3002; &#x5728;&#x524D;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5B66;&#x4E60;&#x4E86;&#x5982;&#x4F55;&#x4F7F;&#x7528;&#x5206;&#x7EC4;&#x5C06;&#x5B57;&#x6BB5;1&#x4E0E;&#x5B57;&#x6BB5;3&#x4EA4;&#x6362;&#x3002; 
&#x60A8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8FD9;&#x4E9B;&#x5F00;&#x5173;&#x5C06;&#x6574;&#x4E2A;&#x5206;&#x7EC4;&#x8F6C;&#x6362;&#x4E3A;&#x5927;&#x5199;&#x6216;&#x5C0F;&#x5199;&#x3002;</p>
<p><strong>employee name&#x5168;&#x90E8;&#x5927;&#x5199;&#xFF0C;employee title&#x5168;&#x90E8;&#x5C0F;&#x5199;</strong>:</p>
<pre><code>$ sed &apos;s/\([^,]*\),\([^,]*\),\(.*\).*/\U\2\E,\1,\L\3/g&apos; employee.txt
JOHN DOE,101,ceo
JASON SMITH,102,it manager
RAJ REDDY,103,sysadmin
ANAND RAM,104,developer
JANE MILLER,105,sales manager
</code></pre><p>&#x5728;&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;{replacement-string}&#x8D70;&#x4EE5;&#x4E0B;&#x6D41;&#x7A0B;</p>
<ul>
<li>\U\2\E -- &#x8FD9;&#x8868;&#x660E;&#x8BE5;&#x5B57;&#x6BB5;&#x662F;&#x7B2C;&#x4E8C;&#x7EC4;&#xFF08;employee name&#xFF09;&#xFF0C;&#x5E94;&#x8BE5;&#x8F6C;&#x6362;&#x4E3A;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x3002; \U&#x5F00;&#x59CB;&#x5927;&#x5199;&#x8F6C;&#x6362;&#xFF0C;\E&#x505C;&#x6B62;&#x8F6C;&#x6362;&#x3002;</li>
<li>\L\3 -- &#x8FD9;&#x8868;&#x660E;&#x8BE5;&#x5B57;&#x6BB5;&#x662F;&#x7B2C;&#x4E09;&#x7EC4;&#xFF08;employee title&#xFF09;&#xFF0C;&#x5E94;&#x8BE5;&#x8F6C;&#x6362;&#x4E3A;&#x5C0F;&#x5199;&#x3002;\L&#x5F00;&#x59CB;&#x5BF9;&#x5176;&#x4F59;&#x5B57;&#x7B26;&#x8FDB;&#x884C;&#x5C0F;&#x5199;&#x8F6C;&#x6362;&#x3002;</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="multiple_group.html" class="navigation navigation-prev " aria-label="Previous page: 18. 分组替换（多组）">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../part3/" class="navigation navigation-next " aria-label="Next page: 说明">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"19.  Gnu Sed {replacement-string}标志","level":"3.15","depth":1,"next":{"title":"说明","level":"4.1","depth":1,"path":"part3/README.md","ref":"part3/README.md","articles":[]},"previous":{"title":"18. 分组替换（多组）","level":"3.14","depth":1,"path":"part2/multiple_group.md","ref":"part2/multiple_group.md","articles":[]},"dir":"ltr"},"config":{"plugins":["emphasize","theme-comscore","-prism","-prism-themes","highlight","simple-page-toc","anchors","anchor-navigation-ex","terminal","-splitter","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{"css":["prism-themes/themes/prism-duotone-sea.css"]},"emphasize":{},"livereload":{},"simple-page-toc":{"maxDepth":3,"skipFirstH1":true},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"mode":"float","pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"isRewritePageTitle":true,"showLevel":true,"isShowTocTitleIcon":true,"printLog":false,"multipleH1":true,"associatedWithSummary":true,"float":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"}},"theme-comscore":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"terminal":{"copyButtons":true,"fade":false,"style":"classic"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"theme":"default","author":"devops007","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Sed-and-Awk-101-Hacks","links":{"sidebar":{"Home":"https://linuxer.io"}},"gitbook":"*"},"file":{"path":"part2/string.md","mtime":"2018-04-18T12:06:34.906Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-09-12T09:00:04.642Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-terminal/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

